/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#include "client.h"


/*
 ==============================================================================

 KEY BUTTONS

 Continuous button event tracking is complicated by the fact that two different
 input sources (say, mouse button 1 and the control key) can both press the
 same button, but the button should only be released when both of the pressing
 keys have been released.

 When a key event issues a button command, it appends its key number as a
 parameter to the command so it can be matched up with the release.

 The last command parameter will be set to the time the event happened, which
 allows exact control even at low framerates when the down and up events may
 both get queued at the same time.

 ==============================================================================
*/

keyButton_t	in_moveForward;
keyButton_t	in_moveBack;
keyButton_t	in_moveRight;
keyButton_t	in_moveLeft;
keyButton_t	in_moveUp;
keyButton_t	in_moveDown;
keyButton_t	in_turnRight;
keyButton_t	in_turnLeft;
keyButton_t	in_lookUp;
keyButton_t	in_lookDown;
keyButton_t	in_speed;
keyButton_t	in_strafe;
keyButton_t	in_buttons[32];

bool		in_mouseLook = false;


/*
 ==================
 IN_KeyDown
 ==================
*/
static void IN_KeyDown (keyButton_t *kb){

	const char	*c;
	int			key;

	c = Cmd_Argv(1);
	if (c[0])
		key = Str_ToInteger(c);
	else
		key = -1;	// Typed manually at the console for continuous down

	if (kb->keys[0] == key || kb->keys[1] == key)
		return;		// Repeating key

	if (!kb->keys[0])
		kb->keys[0] = key;
	else if (!kb->keys[1])
		kb->keys[1] = key;
	else {
		Com_Printf("Three keys down for a button!\n");
		return;
	}

	if (kb->active)
		return;		// Already down

	// Save timestamp
	kb->downTime = Str_ToInteger(Cmd_Argv(2));
	if (!kb->downTime)
		kb->downTime = com_frameTime - com_frameMsec;

	kb->active = true;
	kb->wasPressed = true;
}

/*
 ==================
 IN_KeyUp
 ==================
*/
static void IN_KeyUp (keyButton_t *kb){

	const char	*c;
	int			key;

	c = Cmd_Argv(1);
	if (c[0])
		key = Str_ToInteger(c);
	else {
		// Typed manually at the console, assume for unsticking, so clear all
		kb->keys[0] = kb->keys[1] = 0;

		kb->upTime = com_frameTime;
		kb->active = false;

		return;
	}

	if (kb->keys[0] == key)
		kb->keys[0] = 0;
	else if (kb->keys[1] == key)
		kb->keys[1] = 0;
	else
		return;		// Key up without corresponding down (GUI pass through)

	if (kb->keys[0] || kb->keys[1])
		return;		// Some other key is still holding it down

	if (!kb->active)
		return;		// Already up (this should not happen)

	// Save timestamp
	kb->upTime = Str_ToInteger(Cmd_Argv(2));
	if (!kb->upTime)
		kb->upTime = com_frameTime;

	kb->active = false;
}

/*
 ==================
 IN_KeyState
 ==================
*/
float IN_KeyState (keyButton_t *kb){

	float	frac;
	int		msec;

	if (kb->active){
		// Still down
		msec = com_frameTime - kb->downTime;

		kb->downTime = com_frameTime;
	}
	else {
		// Released
		msec = kb->upTime - kb->downTime;

		kb->downTime = kb->upTime = 0;
	}

	frac = (float)msec / com_frameMsec;

	return M_ClampFloat(frac, 0.0f, 1.0f);
}


/*
 ==============================================================================

 MOUSE MOVEMENT

 ==============================================================================
*/


/*
 ==================
 IN_MouseMove
 ==================
*/
void IN_MouseMove (int x, int y){

	// If the console has the focus, don't move
	if (Key_GetCatchers() & KEYCATCH_CONSOLE)
		return;

	// If a GUI has the focus, move the cursor
	if (Key_GetCatchers() & KEYCATCH_GUI){
		GUI_MouseMove(x, y);
		return;
	}

	// Only accumulate mouse movement in game
	if (cls.state != CS_ACTIVE)
		return;

	cl.mouseX[cl.mouseIndex] += x;
	cl.mouseY[cl.mouseIndex] += y;
}

/*
 ==================
 IN_ClearMouseMovement
 ==================
*/
void IN_ClearMouseMovement (void){

	int		i;

	for (i = 0; i < MAX_MOUSE_SAMPLES; i++){
		cl.mouseX[i] = 0;
		cl.mouseY[i] = 0;
	}
}


// ============================================================================


/*
 ==================
 IN_CenterView_f
 ==================
*/
static void IN_CenterView_f (void){

	cl.viewAngles.pitch = -SHORT2ANGLE(cl.gameDeltaAngles[PITCH]);
}

/*
 ==================
 IN_MouseLookDown_f
 ==================
*/
static void IN_MouseLookDown_f (void){

	in_mouseLook = true;
}

/*
 ==================
 IN_MouseLookUp_f
 ==================
*/
static void IN_MouseLookUp_f (void){

	in_mouseLook = false;

	if (!in_freeLook->integerValue)
		cl.viewAngles.pitch = -SHORT2ANGLE(cl.gameDeltaAngles[PITCH]);
}

/*
 ==================
 IN_MoveForwardDown_f
 ==================
*/
static void IN_MoveForwardDown_f (void){

	IN_KeyDown(&in_moveForward);
}

/*
 ==================
 IN_MoveForwardUp_f
 ==================
*/
static void IN_MoveForwardUp_f (void){

	IN_KeyUp(&in_moveForward);
}

/*
 ==================
 IN_MoveBackDown_f
 ==================
*/
static void IN_MoveBackDown_f (void){

	IN_KeyDown(&in_moveBack);
}

/*
 ==================
 IN_MoveBackUp_f
 ==================
*/
static void IN_MoveBackUp_f (void){

	IN_KeyUp(&in_moveBack);
}

/*
 ==================
 IN_MoveRightDown_f
 ==================
*/
static void IN_MoveRightDown_f (void){

	IN_KeyDown(&in_moveRight);
}

/*
 ==================
 IN_MoveRightUp_f
 ==================
*/
static void IN_MoveRightUp_f (void){

	IN_KeyUp(&in_moveRight);
}

/*
 ==================
 IN_MoveLeftDown_f
 ==================
*/
static void IN_MoveLeftDown_f (void){

	IN_KeyDown(&in_moveLeft);
}

/*
 ==================
 IN_MoveLeftUp_f
 ==================
*/
static void IN_MoveLeftUp_f (void){

	IN_KeyUp(&in_moveLeft);
}

/*
 ==================
 IN_MoveUpDown_f
 ==================
*/
static void IN_MoveUpDown_f (void){

	IN_KeyDown(&in_moveUp);
}

/*
 ==================
 IN_MoveUpUp_f
 ==================
*/
static void IN_MoveUpUp_f (void){

	IN_KeyUp(&in_moveUp);
}

/*
 ==================
 IN_MoveDownDown_f
 ==================
*/
static void IN_MoveDownDown_f (void){

	IN_KeyDown(&in_moveDown);
}

/*
 ==================
 IN_MoveDownUp_f
 ==================
*/
static void IN_MoveDownUp_f (void){

	IN_KeyUp(&in_moveDown);
}

/*
 ==================
 IN_TurnRightDown_f
 ==================
*/
static void IN_TurnRightDown_f (void){

	IN_KeyDown(&in_turnRight);
}

/*
 ==================
 IN_TurnRightUp_f
 ==================
*/
static void IN_TurnRightUp_f (void){

	IN_KeyUp(&in_turnRight);
}

/*
 ==================
 IN_TurnLeftDown_f
 ==================
*/
static void IN_TurnLeftDown_f (void){

	IN_KeyDown(&in_turnLeft);
}

/*
 ==================
 IN_TurnLeftUp_f
 ==================
*/
static void IN_TurnLeftUp_f (void){

	IN_KeyUp(&in_turnLeft);
}

/*
 ==================
 IN_LookUpDown_f
 ==================
*/
static void IN_LookUpDown_f (void){

	IN_KeyDown(&in_lookUp);
}

/*
 ==================
 IN_LookUpUp_f
 ==================
*/
static void IN_LookUpUp_f (void){

	IN_KeyUp(&in_lookUp);
}

/*
 ==================
 IN_LookDownDown_f
 ==================
*/
static void IN_LookDownDown_f (void){

	IN_KeyDown(&in_lookDown);
}

/*
 ==================
 IN_LookDownUp_f
 ==================
*/
static void IN_LookDownUp_f (void){

	IN_KeyUp(&in_lookDown);
}

/*
 ==================
 IN_SpeedDown_f
 ==================
*/
static void IN_SpeedDown_f (void){

	IN_KeyDown(&in_speed);
}

/*
 ==================
 IN_SpeedUp_f
 ==================
*/
static void IN_SpeedUp_f (void){

	IN_KeyUp(&in_speed);
}

/*
 ==================
 IN_StrafeDown_f
 ==================
*/
static void IN_StrafeDown_f (void){

	IN_KeyDown(&in_strafe);
}

/*
 ==================
 IN_StrafeUp_f
 ==================
*/
static void IN_StrafeUp_f (void){

	IN_KeyUp(&in_strafe);
}

/*
 ==================
 IN_Button0Down_f
 ==================
*/
static void IN_Button0Down_f (void){

	IN_KeyDown(&in_buttons[0]);
}

/*
 ==================
 IN_Button0Up_f
 ==================
*/
static void IN_Button0Up_f (void){

	IN_KeyUp(&in_buttons[0]);
}

/*
 ==================
 IN_Button1Down_f
 ==================
*/
static void IN_Button1Down_f (void){

	IN_KeyDown(&in_buttons[1]);
}

/*
 ==================
 IN_Button1Up_f
 ==================
*/
static void IN_Button1Up_f (void){

	IN_KeyUp(&in_buttons[1]);
}

/*
 ==================
 IN_Button2Down_f
 ==================
*/
static void IN_Button2Down_f (void){

	IN_KeyDown(&in_buttons[2]);
}

/*
 ==================
 IN_Button2Up_f
 ==================
*/
static void IN_Button2Up_f (void){

	IN_KeyUp(&in_buttons[2]);
}

/*
 ==================
 IN_Button3Down_f
 ==================
*/
static void IN_Button3Down_f (void){

	IN_KeyDown(&in_buttons[3]);
}

/*
 ==================
 IN_Button3Up_f
 ==================
*/
static void IN_Button3Up_f (void){

	IN_KeyUp(&in_buttons[3]);
}

/*
 ==================
 IN_Button4Down_f
 ==================
*/
static void IN_Button4Down_f (void){

	IN_KeyDown(&in_buttons[4]);
}

/*
 ==================
 IN_Button4Up_f
 ==================
*/
static void IN_Button4Up_f (void){

	IN_KeyUp(&in_buttons[4]);
}

/*
 ==================
 IN_Button5Down_f
 ==================
*/
static void IN_Button5Down_f (void){

	IN_KeyDown(&in_buttons[5]);
}

/*
 ==================
 IN_Button5Up_f
 ==================
*/
static void IN_Button5Up_f (void){

	IN_KeyUp(&in_buttons[5]);
}

/*
 ==================
 IN_Button6Down_f
 ==================
*/
static void IN_Button6Down_f (void){

	IN_KeyDown(&in_buttons[6]);
}

/*
 ==================
 IN_Button6Up_f
 ==================
*/
static void IN_Button6Up_f (void){

	IN_KeyUp(&in_buttons[6]);
}

/*
 ==================
 IN_Button7Down_f
 ==================
*/
static void IN_Button7Down_f (void){

	IN_KeyDown(&in_buttons[7]);
}

/*
 ==================
 IN_Button7Up_f
 ==================
*/
static void IN_Button7Up_f (void){

	IN_KeyUp(&in_buttons[7]);
}

/*
 ==================
 IN_Button8Down_f
 ==================
*/
static void IN_Button8Down_f (void){

	IN_KeyDown(&in_buttons[8]);
}

/*
 ==================
 IN_Button8Up_f
 ==================
*/
static void IN_Button8Up_f (void){

	IN_KeyUp(&in_buttons[8]);
}

/*
 ==================
 IN_Button9Down_f
 ==================
*/
static void IN_Button9Down_f (void){

	IN_KeyDown(&in_buttons[9]);
}

/*
 ==================
 IN_Button9Up_f
 ==================
*/
static void IN_Button9Up_f (void){

	IN_KeyUp(&in_buttons[9]);
}

/*
 ==================
 IN_Button10Down_f
 ==================
*/
static void IN_Button10Down_f (void){

	IN_KeyDown(&in_buttons[10]);
}

/*
 ==================
 IN_Button10Up_f
 ==================
*/
static void IN_Button10Up_f (void){

	IN_KeyUp(&in_buttons[10]);
}

/*
 ==================
 IN_Button11Down_f
 ==================
*/
static void IN_Button11Down_f (void){

	IN_KeyDown(&in_buttons[11]);
}

/*
 ==================
 IN_Button11Up_f
 ==================
*/
static void IN_Button11Up_f (void){

	IN_KeyUp(&in_buttons[11]);
}

/*
 ==================
 IN_Button12Down_f
 ==================
*/
static void IN_Button12Down_f (void){

	IN_KeyDown(&in_buttons[12]);
}

/*
 ==================
 IN_Button12Up_f
 ==================
*/
static void IN_Button12Up_f (void){

	IN_KeyUp(&in_buttons[12]);
}

/*
 ==================
 IN_Button13Down_f
 ==================
*/
static void IN_Button13Down_f (void){

	IN_KeyDown(&in_buttons[13]);
}

/*
 ==================
 IN_Button13Up_f
 ==================
*/
static void IN_Button13Up_f (void){

	IN_KeyUp(&in_buttons[13]);
}

/*
 ==================
 IN_Button14Down_f
 ==================
*/
static void IN_Button14Down_f (void){

	IN_KeyDown(&in_buttons[14]);
}

/*
 ==================
 IN_Button14Up_f
 ==================
*/
static void IN_Button14Up_f (void){

	IN_KeyUp(&in_buttons[14]);
}

/*
 ==================
 IN_Button15Down_f
 ==================
*/
static void IN_Button15Down_f (void){

	IN_KeyDown(&in_buttons[15]);
}

/*
 ==================
 IN_Button15Up_f
 ==================
*/
static void IN_Button15Up_f (void){

	IN_KeyUp(&in_buttons[15]);
}

/*
 ==================
 IN_Button16Down_f
 ==================
*/
static void IN_Button16Down_f (void){

	IN_KeyDown(&in_buttons[16]);
}

/*
 ==================
 IN_Button16Up_f
 ==================
*/
static void IN_Button16Up_f (void){

	IN_KeyUp(&in_buttons[16]);
}

/*
 ==================
 IN_Button17Down_f
 ==================
*/
static void IN_Button17Down_f (void){

	IN_KeyDown(&in_buttons[17]);
}

/*
 ==================
 IN_Button17Up_f
 ==================
*/
static void IN_Button17Up_f (void){

	IN_KeyUp(&in_buttons[17]);
}

/*
 ==================
 IN_Button18Down_f
 ==================
*/
static void IN_Button18Down_f (void){

	IN_KeyDown(&in_buttons[18]);
}

/*
 ==================
 IN_Button18Up_f
 ==================
*/
static void IN_Button18Up_f (void){

	IN_KeyUp(&in_buttons[18]);
}

/*
 ==================
 IN_Button19Down_f
 ==================
*/
static void IN_Button19Down_f (void){

	IN_KeyDown(&in_buttons[19]);
}

/*
 ==================
 IN_Button19Up_f
 ==================
*/
static void IN_Button19Up_f (void){

	IN_KeyUp(&in_buttons[19]);
}

/*
 ==================
 IN_Button20Down_f
 ==================
*/
static void IN_Button20Down_f (void){

	IN_KeyDown(&in_buttons[20]);
}

/*
 ==================
 IN_Button20Up_f
 ==================
*/
static void IN_Button20Up_f (void){

	IN_KeyUp(&in_buttons[20]);
}

/*
 ==================
 IN_Button21Down_f
 ==================
*/
static void IN_Button21Down_f (void){

	IN_KeyDown(&in_buttons[21]);
}

/*
 ==================
 IN_Button21Up_f
 ==================
*/
static void IN_Button21Up_f (void){

	IN_KeyUp(&in_buttons[21]);
}

/*
 ==================
 IN_Button22Down_f
 ==================
*/
static void IN_Button22Down_f (void){

	IN_KeyDown(&in_buttons[22]);
}

/*
 ==================
 IN_Button22Up_f
 ==================
*/
static void IN_Button22Up_f (void){

	IN_KeyUp(&in_buttons[22]);
}

/*
 ==================
 IN_Button23Down_f
 ==================
*/
static void IN_Button23Down_f (void){

	IN_KeyDown(&in_buttons[23]);
}

/*
 ==================
 IN_Button23Up_f
 ==================
*/
static void IN_Button23Up_f (void){

	IN_KeyUp(&in_buttons[23]);
}

/*
 ==================
 IN_Button24Down_f
 ==================
*/
static void IN_Button24Down_f (void){

	IN_KeyDown(&in_buttons[24]);
}

/*
 ==================
 IN_Button24Up_f
 ==================
*/
static void IN_Button24Up_f (void){

	IN_KeyUp(&in_buttons[24]);
}

/*
 ==================
 IN_Button25Down_f
 ==================
*/
static void IN_Button25Down_f (void){

	IN_KeyDown(&in_buttons[25]);
}

/*
 ==================
 IN_Button25Up_f
 ==================
*/
static void IN_Button25Up_f (void){

	IN_KeyUp(&in_buttons[25]);
}

/*
 ==================
 IN_Button26Down_f
 ==================
*/
static void IN_Button26Down_f (void){

	IN_KeyDown(&in_buttons[26]);
}

/*
 ==================
 IN_Button26Up_f
 ==================
*/
static void IN_Button26Up_f (void){

	IN_KeyUp(&in_buttons[26]);
}

/*
 ==================
 IN_Button27Down_f
 ==================
*/
static void IN_Button27Down_f (void){

	IN_KeyDown(&in_buttons[27]);
}

/*
 ==================
 IN_Button27Up_f
 ==================
*/
static void IN_Button27Up_f (void){

	IN_KeyUp(&in_buttons[27]);
}

/*
 ==================
 IN_Button28Down_f
 ==================
*/
static void IN_Button28Down_f (void){

	IN_KeyDown(&in_buttons[28]);
}

/*
 ==================
 IN_Button28Up_f
 ==================
*/
static void IN_Button28Up_f (void){

	IN_KeyUp(&in_buttons[28]);
}

/*
 ==================
 IN_Button29Down_f
 ==================
*/
static void IN_Button29Down_f (void){

	IN_KeyDown(&in_buttons[29]);
}

/*
 ==================
 IN_Button29Up_f
 ==================
*/
static void IN_Button29Up_f (void){

	IN_KeyUp(&in_buttons[29]);
}

/*
 ==================
 IN_Button30Down_f
 ==================
*/
static void IN_Button30Down_f (void){

	IN_KeyDown(&in_buttons[30]);
}

/*
 ==================
 IN_Button30Up_f
 ==================
*/
static void IN_Button30Up_f (void){

	IN_KeyUp(&in_buttons[30]);
}

/*
 ==================
 IN_Button31Down_f
 ==================
*/
static void IN_Button31Down_f (void){

	IN_KeyDown(&in_buttons[31]);
}

/*
 ==================
 IN_Button31Up_f
 ==================
*/
static void IN_Button31Up_f (void){

	IN_KeyUp(&in_buttons[31]);
}

/*
 ==================
 IN_AddCommands
 ==================
*/
void IN_AddCommands (void){

	Cmd_AddCommand("centerView", IN_CenterView_f, "Centers the view");
	Cmd_AddCommand("+mouseLook", IN_MouseLookDown_f, NULL);
	Cmd_AddCommand("-mouseLook", IN_MouseLookUp_f, NULL);
	Cmd_AddCommand("+moveForward", IN_MoveForwardDown_f, NULL);
	Cmd_AddCommand("-moveForward", IN_MoveForwardUp_f, NULL);
	Cmd_AddCommand("+moveBack", IN_MoveBackDown_f, NULL);
	Cmd_AddCommand("-moveBack", IN_MoveBackUp_f, NULL);
	Cmd_AddCommand("+moveRight", IN_MoveRightDown_f, NULL);
	Cmd_AddCommand("-moveRight", IN_MoveRightUp_f, NULL);
	Cmd_AddCommand("+moveLeft", IN_MoveLeftDown_f, NULL);
	Cmd_AddCommand("-moveLeft", IN_MoveLeftUp_f, NULL);
	Cmd_AddCommand("+moveUp", IN_MoveUpDown_f, NULL);
	Cmd_AddCommand("-moveUp", IN_MoveUpUp_f, NULL);
	Cmd_AddCommand("+moveDown", IN_MoveDownDown_f, NULL);
	Cmd_AddCommand("-moveDown", IN_MoveDownUp_f, NULL);
	Cmd_AddCommand("+turnRight", IN_TurnRightDown_f, NULL);
	Cmd_AddCommand("-turnRight", IN_TurnRightUp_f, NULL);
	Cmd_AddCommand("+turnLeft", IN_TurnLeftDown_f, NULL);
	Cmd_AddCommand("-turnLeft", IN_TurnLeftUp_f, NULL);
	Cmd_AddCommand("+lookUp", IN_LookUpDown_f, NULL);
	Cmd_AddCommand("-lookUp", IN_LookUpUp_f, NULL);
	Cmd_AddCommand("+lookDown", IN_LookDownDown_f, NULL);
	Cmd_AddCommand("-lookDown", IN_LookDownUp_f, NULL);
	Cmd_AddCommand("+speed", IN_SpeedDown_f, NULL);
	Cmd_AddCommand("-speed", IN_SpeedUp_f, NULL);
	Cmd_AddCommand("+strafe", IN_StrafeDown_f, NULL);
	Cmd_AddCommand("-strafe", IN_StrafeUp_f, NULL);
	Cmd_AddCommand("+button0", IN_Button0Down_f, NULL);
	Cmd_AddCommand("-button0", IN_Button0Up_f, NULL);
	Cmd_AddCommand("+button1", IN_Button1Down_f, NULL);
	Cmd_AddCommand("-button1", IN_Button1Up_f, NULL);
	Cmd_AddCommand("+button2", IN_Button2Down_f, NULL);
	Cmd_AddCommand("-button2", IN_Button2Up_f, NULL);
	Cmd_AddCommand("+button3", IN_Button3Down_f, NULL);
	Cmd_AddCommand("-button3", IN_Button3Up_f, NULL);
	Cmd_AddCommand("+button4", IN_Button4Down_f, NULL);
	Cmd_AddCommand("-button4", IN_Button4Up_f, NULL);
	Cmd_AddCommand("+button5", IN_Button5Down_f, NULL);
	Cmd_AddCommand("-button5", IN_Button5Up_f, NULL);
	Cmd_AddCommand("+button6", IN_Button6Down_f, NULL);
	Cmd_AddCommand("-button6", IN_Button6Up_f, NULL);
	Cmd_AddCommand("+button7", IN_Button7Down_f, NULL);
	Cmd_AddCommand("-button7", IN_Button7Up_f, NULL);
	Cmd_AddCommand("+button8", IN_Button8Down_f, NULL);
	Cmd_AddCommand("-button8", IN_Button8Up_f, NULL);
	Cmd_AddCommand("+button9", IN_Button9Down_f, NULL);
	Cmd_AddCommand("-button9", IN_Button9Up_f, NULL);
	Cmd_AddCommand("+button10", IN_Button10Down_f, NULL);
	Cmd_AddCommand("-button10", IN_Button10Up_f, NULL);
	Cmd_AddCommand("+button11", IN_Button11Down_f, NULL);
	Cmd_AddCommand("-button11", IN_Button11Up_f, NULL);
	Cmd_AddCommand("+button12", IN_Button12Down_f, NULL);
	Cmd_AddCommand("-button12", IN_Button12Up_f, NULL);
	Cmd_AddCommand("+button13", IN_Button13Down_f, NULL);
	Cmd_AddCommand("-button13", IN_Button13Up_f, NULL);
	Cmd_AddCommand("+button14", IN_Button14Down_f, NULL);
	Cmd_AddCommand("-button14", IN_Button14Up_f, NULL);
	Cmd_AddCommand("+button15", IN_Button15Down_f, NULL);
	Cmd_AddCommand("-button15", IN_Button15Up_f, NULL);
	Cmd_AddCommand("+button16", IN_Button16Down_f, NULL);
	Cmd_AddCommand("-button16", IN_Button16Up_f, NULL);
	Cmd_AddCommand("+button17", IN_Button17Down_f, NULL);
	Cmd_AddCommand("-button17", IN_Button17Up_f, NULL);
	Cmd_AddCommand("+button18", IN_Button18Down_f, NULL);
	Cmd_AddCommand("-button18", IN_Button18Up_f, NULL);
	Cmd_AddCommand("+button19", IN_Button19Down_f, NULL);
	Cmd_AddCommand("-button19", IN_Button19Up_f, NULL);
	Cmd_AddCommand("+button20", IN_Button20Down_f, NULL);
	Cmd_AddCommand("-button20", IN_Button20Up_f, NULL);
	Cmd_AddCommand("+button21", IN_Button21Down_f, NULL);
	Cmd_AddCommand("-button21", IN_Button21Up_f, NULL);
	Cmd_AddCommand("+button22", IN_Button22Down_f, NULL);
	Cmd_AddCommand("-button22", IN_Button22Up_f, NULL);
	Cmd_AddCommand("+button23", IN_Button23Down_f, NULL);
	Cmd_AddCommand("-button23", IN_Button23Up_f, NULL);
	Cmd_AddCommand("+button24", IN_Button24Down_f, NULL);
	Cmd_AddCommand("-button24", IN_Button24Up_f, NULL);
	Cmd_AddCommand("+button25", IN_Button25Down_f, NULL);
	Cmd_AddCommand("-button25", IN_Button25Up_f, NULL);
	Cmd_AddCommand("+button26", IN_Button26Down_f, NULL);
	Cmd_AddCommand("-button26", IN_Button26Up_f, NULL);
	Cmd_AddCommand("+button27", IN_Button27Down_f, NULL);
	Cmd_AddCommand("-button27", IN_Button27Up_f, NULL);
	Cmd_AddCommand("+button28", IN_Button28Down_f, NULL);
	Cmd_AddCommand("-button28", IN_Button28Up_f, NULL);
	Cmd_AddCommand("+button29", IN_Button29Down_f, NULL);
	Cmd_AddCommand("-button29", IN_Button29Up_f, NULL);
	Cmd_AddCommand("+button30", IN_Button30Down_f, NULL);
	Cmd_AddCommand("-button30", IN_Button30Up_f, NULL);
	Cmd_AddCommand("+button31", IN_Button31Down_f, NULL);
	Cmd_AddCommand("-button31", IN_Button31Up_f, NULL);
}

/*
 ==================
 IN_RemoveCommands
 ==================
*/
void IN_RemoveCommands (void){

	Cmd_RemoveCommand("centerView");
	Cmd_RemoveCommand("+mouseLook");
	Cmd_RemoveCommand("-mouseLook");
	Cmd_RemoveCommand("+moveForward");
	Cmd_RemoveCommand("-moveForward");
	Cmd_RemoveCommand("+moveBack");
	Cmd_RemoveCommand("-moveBack");
	Cmd_RemoveCommand("+moveRight");
	Cmd_RemoveCommand("-moveRight");
	Cmd_RemoveCommand("+moveLeft");
	Cmd_RemoveCommand("-moveLeft");
	Cmd_RemoveCommand("+moveUp");
	Cmd_RemoveCommand("-moveUp");
	Cmd_RemoveCommand("+moveDown");
	Cmd_RemoveCommand("-moveDown");
	Cmd_RemoveCommand("+turnRight");
	Cmd_RemoveCommand("-turnRight");
	Cmd_RemoveCommand("+turnLeft");
	Cmd_RemoveCommand("-turnLeft");
	Cmd_RemoveCommand("+lookUp");
	Cmd_RemoveCommand("-lookUp");
	Cmd_RemoveCommand("+lookDown");
	Cmd_RemoveCommand("-lookDown");
	Cmd_RemoveCommand("+speed");
	Cmd_RemoveCommand("-speed");
	Cmd_RemoveCommand("+strafe");
	Cmd_RemoveCommand("-strafe");
	Cmd_RemoveCommand("+button0");
	Cmd_RemoveCommand("-button0");
	Cmd_RemoveCommand("+button1");
	Cmd_RemoveCommand("-button1");
	Cmd_RemoveCommand("+button2");
	Cmd_RemoveCommand("-button2");
	Cmd_RemoveCommand("+button3");
	Cmd_RemoveCommand("-button3");
	Cmd_RemoveCommand("+button4");
	Cmd_RemoveCommand("-button4");
	Cmd_RemoveCommand("+button5");
	Cmd_RemoveCommand("-button5");
	Cmd_RemoveCommand("+button6");
	Cmd_RemoveCommand("-button6");
	Cmd_RemoveCommand("+button7");
	Cmd_RemoveCommand("-button7");
	Cmd_RemoveCommand("+button8");
	Cmd_RemoveCommand("-button8");
	Cmd_RemoveCommand("+button9");
	Cmd_RemoveCommand("-button9");
	Cmd_RemoveCommand("+button10");
	Cmd_RemoveCommand("-button10");
	Cmd_RemoveCommand("+button11");
	Cmd_RemoveCommand("-button11");
	Cmd_RemoveCommand("+button12");
	Cmd_RemoveCommand("-button12");
	Cmd_RemoveCommand("+button13");
	Cmd_RemoveCommand("-button13");
	Cmd_RemoveCommand("+button14");
	Cmd_RemoveCommand("-button14");
	Cmd_RemoveCommand("+button15");
	Cmd_RemoveCommand("-button15");
	Cmd_RemoveCommand("+button16");
	Cmd_RemoveCommand("-button16");
	Cmd_RemoveCommand("+button17");
	Cmd_RemoveCommand("-button17");
	Cmd_RemoveCommand("+button18");
	Cmd_RemoveCommand("-button18");
	Cmd_RemoveCommand("+button19");
	Cmd_RemoveCommand("-button19");
	Cmd_RemoveCommand("+button20");
	Cmd_RemoveCommand("-button20");
	Cmd_RemoveCommand("+button21");
	Cmd_RemoveCommand("-button21");
	Cmd_RemoveCommand("+button22");
	Cmd_RemoveCommand("-button22");
	Cmd_RemoveCommand("+button23");
	Cmd_RemoveCommand("-button23");
	Cmd_RemoveCommand("+button24");
	Cmd_RemoveCommand("-button24");
	Cmd_RemoveCommand("+button25");
	Cmd_RemoveCommand("-button25");
	Cmd_RemoveCommand("+button26");
	Cmd_RemoveCommand("-button26");
	Cmd_RemoveCommand("+button27");
	Cmd_RemoveCommand("-button27");
	Cmd_RemoveCommand("+button28");
	Cmd_RemoveCommand("-button28");
	Cmd_RemoveCommand("+button29");
	Cmd_RemoveCommand("-button29");
	Cmd_RemoveCommand("+button30");
	Cmd_RemoveCommand("-button30");
	Cmd_RemoveCommand("+button31");
	Cmd_RemoveCommand("-button31");
}
